import yaml
from baseTools.my_logger import logger
import traceback

def read_my_yaml(file_name, key_word = None):
    """
    读取yaml文件内的测试数据
    :param file_name:
    :return:
    """
    logger.info("读取测试用例数据文件，文件名：{}".format(file_name))
    try:
        with open(file_name, encoding='utf-8') as f:
            values = yaml.safe_load(f)
            logger.info("读取测试用例数据文件成功！")
            if key_word:
                new_values = []
                for value in values:
                    if value.get("key_word") == key_word:
                        new_values.append(value)
                return new_values
            else:
                return values
    except:
        logger.error("读取测试用例数据文件失败，报错信息为：{}".format(traceback.format_exc()))
        raise "用例数据读取失败"
print(read_my_yaml(r"D:\PycharmProjects\PythonProject\UIAutoText\case\caseDatas\org_test_case.yaml", key_word="create_org"))
